#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : shop.py
# @Author: shadow
# @Date  : 2019/11/19
# @Desc  :

from functools import reduce
products = [['iphone', 6888], ['MacPro', 14800], ['小米6', 2499], ['Coffee', 31], ['Book', 60], ['Nike', 699]]
shop_cost = []
shop_car = []


def goods_list():
    print("---------------goods list of my shop--------------")
    for i in products:
        print(products.index(i), i[0], i[1])


def shop_calc(goods):
    goods_count = len(products)
    goods_name = [i[0] for i in products]
    goods_index = -1
    if goods in goods_name:
        goods_index = goods_name.index(goods)
    elif goods.isdigit() and int(goods) < goods_count:
        goods_index = int(goods)
    else:
        print("*********Error name or num of goods!**************")

    if goods_index != -1:
        print("===========get %s" % goods_name[goods_index])
        shop_car.append(products[goods_index][0])
        shop_cost.append(products[goods_index][1])


if __name__ == '__main__':
    while True:
        goods_list()
        n = input("Please input the name or num of goods you want:")
        if n == "p":
            break
        else:
            shop_calc(n)
            print("-"*50)

    print(shop_car, shop_cost, reduce(lambda x,y:x+y, shop_cost))
